<template>
<el-container>
  <el-header style="height: auto;">
    <el-form>
      <el-row class="back">
        <el-col>
          <el-button @click="toBack" size="small" type="primary">返回</el-button>
        </el-col>
      </el-row>
      <el-row>
        <el-col :xl="{ span: 4 }" :lg="{ span: 4 }">
          <el-form-item label="累积已用" label-width="80px">
            <el-input size="small" v-model="cardFlowActUsed" style="width: 100%;"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="{ span: 4 }" :lg="{ span: 4 }">
          <el-form-item label="累积剩余" label-width="80px">
            <el-input size="small" v-model="carFlowSurplus" style="width: 100%;"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </el-header>
  <el-main style="height: auto;">
    <el-table :header-cell-style="{ 'background':$store.state.app.tableBgColor,'color':'#606266' }" :data="tableData" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange" v-loading.fullscreen="tableLoading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.2)">
      <el-table-column type="selection" align="center"></el-table-column>
      <el-table-column prop="cardNumber" label="业务号码" align="center">
        <!--template(slot-scope="scope")el-button(type="text" @click="toUsage") {{ scope.row }}
        -->
      </el-table-column>
      <el-table-column prop="dictAgentTypeName" label="所属流量池" align="center"></el-table-column>
      <el-table-column prop="dictRealNameName" label="卡状态" align="center"></el-table-column>
      <el-table-column prop="cardFlowActUsed" label="总用量" align="center"></el-table-column>
      <el-table-column prop="pidName" label="当月用量" align="center"></el-table-column>
      <el-table-column prop="employeeName" label="单位" align="center"></el-table-column>
      <el-table-column prop="alipayName" label="卡用途" align="center"></el-table-column>
    </el-table>
    <div class="block"><span class="demonstration"></span>
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-size="10" layout="prev, pager, next, jumper" :page-count="maxPage" :hide-on-single-page="value" background></el-pagination>
    </div>
  </el-main>
</el-container>
</template>

<script>
  import { viewSecondaryFlowPoolSubordinateCard } from '@/api/getData'

  export default {
    name: 'NextCardList',
    data() {
      return {
        maxPage: 1,
        tableData: [],
        pageSize: 10,
        currentPage: 1,
        ascs: [],
        descs: [],
        multipleSelection: [],
        tableLoading: false,
        cardFlowActUsed: '',
        carFlowSurplus: '',
        value: false,
        secondPoolFlowId : '',
        active : ''
      }
    },
    created() {
      this.secondPoolFlowId = this.$route.params.id
      this.active = this.$route.params.active
      this.initData()
    },
    methods: {
      async initData() {
        const returnData = await viewSecondaryFlowPoolSubordinateCard({
          secondPoolFlowId : this.secondPoolFlowId,
          dictChannelCardStatus : this.active,
          page: {
            current: this.currentPage + '',
            size: this.pageSize + '',
            ascs: this.ascs,
            descs: this.descs
          }
        }, {
          obj: this,
          key: 'tableLoading'
        })
        this.tableData = []
        //console.log(returnData)
        if (returnData._result) {
          this.maxPage = Math.ceil(returnData.data.total / this.pageSize) // 分页的最大页数
          // 数据回显
          returnData.data.records.map(item => {
            const obj = {}
            obj.id = item.id
            obj.id = item.id
            obj.agentName = item.agentName // 代理名称
            obj.dictAgentTypeName = item.dictAgentTypeName // 代理类型
            obj.dictRealNameName = item.dictRealNameName // 实名类型
            obj.dictStatusName = item.dictStatusName // 用户状态
            obj.pidName = item.pidName // 所属关系
            obj.employeeName = item.employeeName // 业务员
            obj.telephone = item.telephone // 代理联系电话
            obj.alipayName = item.alipayName // 支付宝户名
            obj.alipayLoginName = item.alipayLoginName // 支付宝账号
            obj.cardCount = item.cardCount // 拥有卡数
            obj.balance = item.balance // 余额
            obj.insertTimeDate = item.insertTimeDate // 创建时间
            this.tableData.push(obj)
          })
          this.tableLoading = false
        }
      },
      handleSelectionChange(val) {
        this.multipleSelection = val
      },
      handleSizeChange(val) {
        //console.log(`每页 ${val} 条`)
        this.pageSize = val
      },
      handleCurrentChange(val) {
        //console.log(`当前页: ${val}`)
        this.currentPage = val
        this.initData()
      },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done()
          })
          .catch(_ => {})
      },
      toUsage() {
        this.$router.push({ path: '/package/usage' })
      },
      toBack() {
        this.$router.back(-1);
      }
    }
  }
</script>

<style scoped lang="scss">
  .el-container {
    .el-header {
      margin-top: 5vh;
      .back {
        margin-bottom: 3vh;
      }
    }
    .el-main {
      .block {
        float: right;
      }
    }
  }
</style>
